package com.dinzeer.resonantisshelomoh.event;

import com.dinzeer.legendreliclib.lib.event.TypeMakerPressedEvent;
import com.dinzeer.legendreliclib.lib.key.LRModKeyMappings;
import com.dinzeer.legendreliclib.lib.util.slashblade.SlashBladeUtil;
import com.dinzeer.legendreliclib.lib.util.text.AdvancedGradientTextHelper;
import com.dinzeer.legendreliclib.lib.util.text.ColorPreset;
import com.dinzeer.resonantisshelomoh.Resonantisshelomoh;
import com.dinzeer.resonantisshelomoh.regsiter.RSSpecialEffectsRegistry;
import com.dinzeer.resonantisshelomoh.regsiter.RSslashartRegsitry;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.RegistryObject;

@Mod.EventBusSubscriber
public class ChangeType {










    @SubscribeEvent
    @OnlyIn(Dist.CLIENT)
    public static void onItemTooltip(ItemTooltipEvent event) {
        ItemStack stack = event.getItemStack();
    if (stack.getItem() instanceof ItemSlashBlade){
        ISlashBladeState state= SlashBladeUtil.getState(stack);
        if(state.getTranslationKey().equals("item.resonantisshelomoh.temperance")){
            for (int i=1;i<2 ;i++) {
                event.getToolTip().add(Component.translatable("tooltip.resonantisshelomoh.temperance_tip_"+ i).withStyle(ChatFormatting.WHITE));
            }
        }
        if(state.getTranslationKey().equals("item.resonantisshelomoh.reflection")){
            for (int i=1;i<4 ;i++) {
                event.getToolTip().add(Component.translatable("tooltip.resonantisshelomoh.reflection_tip_"+ i).withStyle(ChatFormatting.WHITE));
            }
        }
        if(state.getTranslationKey().equals("item.resonantisshelomoh.reversed")){
            for (int i=1;i<3 ;i++) {
                event.getToolTip().add(Component.translatable("tooltip.resonantisshelomoh.reversed_tip_"+ i).withStyle(ChatFormatting.WHITE));
            }
        }
        if(state.getTranslationKey().equals("item.resonantisshelomoh.solomon")){
            for (int i=1;i<7 ;i++) {
                event.getToolTip().add(Component.translatable("tooltip.resonantisshelomoh.solomon_tip_"+ i).withStyle(ChatFormatting.BLUE));
            }
            String originalName =Component.translatable("tooltip.resonantisshelomoh.type_make", LRModKeyMappings.TypeMaker.getKey().getDisplayName()).getString();
            Component newName= AdvancedGradientTextHelper.createGradientText(originalName,
                    ColorPreset.CYAN_AQUA,
                    AdvancedGradientTextHelper.GradientMode.FLOW);
            event.getToolTip().add(newName);
        }
        if(state.getTranslationKey().equals("item.resonantisshelomoh.reverse_solomon")){
            for (int i=1;i<8 ;i++) {
                event.getToolTip().add(Component.translatable("tooltip.resonantisshelomoh.reverse_solomon_tip_"+ i).withStyle(ChatFormatting.DARK_RED));
            }

            String originalName =Component.translatable("tooltip.resonantisshelomoh.type_make", LRModKeyMappings.TypeMaker.getKey().getDisplayName()).getString();
            Component newName= AdvancedGradientTextHelper.createGradientText(originalName,
                    ColorPreset.RED_EMBER,
                    AdvancedGradientTextHelper.GradientMode.WAVE);
            event.getToolTip().add(newName);
        }
    }
    }



    @SubscribeEvent
    public static void changeType(TypeMakerPressedEvent event) {
        Player player=event.getEntity();
        if (player.getMainHandItem().getItem() instanceof ItemSlashBlade){
        ISlashBladeState state= SlashBladeUtil.getState(player.getMainHandItem());
        if(state.getTranslationKey().equals("item.resonantisshelomoh.solomon")){

            player.sendSystemMessage(Component.translatable("tips.resonantisshelomoh.dark_1").withStyle(ChatFormatting.DARK_RED));
            player.sendSystemMessage(Component.translatable("tips.resonantisshelomoh.dark_2").withStyle(ChatFormatting.DARK_RED));
            player.sendSystemMessage(Component.translatable("tips.resonantisshelomoh.dark_3").withStyle(ChatFormatting.DARK_RED));
            moveType(state,
                    "item.resonantisshelomoh.reverse_solomon",
                    Resonantisshelomoh.prefix("model/solmen/reverse_solomon.obj"),
                    Resonantisshelomoh.prefix("model/solmen/reverse_solomon.png"),
                    RSSpecialEffectsRegistry.OccupyingHeart,
                    RSSpecialEffectsRegistry.SeizetheBlood,
                    RSSpecialEffectsRegistry.CompassionforTorture,
                    RSSpecialEffectsRegistry.Theinescapableguilt,
                    RSSpecialEffectsRegistry.HelplessRest,
                    RSSpecialEffectsRegistry.Anuntraceablehope,
                    16711680
                    );
            state.setSlashArtsKey(RSslashartRegsitry.ALLOVEREX.getId());
        }else
        if (state.getTranslationKey().equals("item.resonantisshelomoh.reverse_solomon")){
            player.sendSystemMessage(Component.translatable("tips.resonantisshelomoh.white_1").withStyle(ChatFormatting.AQUA));
            player.sendSystemMessage(Component.translatable("tips.resonantisshelomoh.white_2").withStyle(ChatFormatting.AQUA));
            player.sendSystemMessage(Component.translatable("tips.resonantisshelomoh.white_3").withStyle(ChatFormatting.AQUA));
            player.sendSystemMessage(Component.translatable("tips.resonantisshelomoh.white_4").withStyle(ChatFormatting.AQUA));
            moveType(state,
                    "item.resonantisshelomoh.solomon",
                    Resonantisshelomoh.prefix("model/solmen/solomon.obj"),
                    Resonantisshelomoh.prefix("model/solmen/solomon.png"),
                    RSSpecialEffectsRegistry.Theinescapableguilt,
                    RSSpecialEffectsRegistry.HelplessRest,
                    RSSpecialEffectsRegistry.Anuntraceablehope,
                    RSSpecialEffectsRegistry.OccupyingHeart,
                    RSSpecialEffectsRegistry.SeizetheBlood,
                    RSSpecialEffectsRegistry.CompassionforTorture,
                    21503
            );
            state.setSlashArtsKey(RSslashartRegsitry.ALLOVEREX2.getId());
        }
        }
    }
    private static void moveType(ISlashBladeState state,
                                 String TranslationKey,
                                 ResourceLocation ModelPath,
                                 ResourceLocation TexturePath,
                                 RegistryObject<SpecialEffect> AddSe1,
                                 RegistryObject<SpecialEffect> AddSe2,
                                 RegistryObject<SpecialEffect> AddSe3,
                                 RegistryObject<SpecialEffect> RemoveSe1,
                                 RegistryObject<SpecialEffect> RemoveSe2,
                                 RegistryObject<SpecialEffect> RemoveSe3,
                                 int colorCode){
        state.setTranslationKey(TranslationKey);
        state.setModel(ModelPath);
        state.setTexture(TexturePath);
        state.addSpecialEffect(AddSe1.getId());
        state.addSpecialEffect(AddSe2.getId());
        state.addSpecialEffect(AddSe3.getId());
        state.removeSpecialEffect(RemoveSe1.getId());
        state.removeSpecialEffect(RemoveSe2.getId());
        state.removeSpecialEffect(RemoveSe3.getId());
        state.setColorCode(colorCode);
    }
}
